﻿using Sc.Domain;
using Sc.Persistence;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sc.Service
{
    public class CostRegisterService
    {
        private readonly CostRegisterDAO dal = new CostRegisterDAO();
        #region  BasicMethod
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(CostRegister model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CostRegister model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CostRegister GetModel(int Id)
        {

            return dal.GetModel(Id);
        }
        #endregion  BasicMethod
        #region UserMethod
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="pageIndex">当前第几页</param>
        /// <param name="userId">用户ID</param>
        /// <returns></returns>
        public CommModel<CostRegister> GetPageData(int pageSize, int pageIndex,int userId)
        {
            string where = " AND Driver=" + userId;
            Hashtable param = new Hashtable();
            param.Add("A1", pageIndex);
            param.Add("A2", pageSize);
            param.Add("A3", where);
            param.Add("A4", "Vw_CostReg");
            param.Add("A5", "CostTime DESC");
            var ht = CommDAO.CommPagination(param);
            DataTable dt = ht["data"] as DataTable;
            List<CostRegister> list = new List<CostRegister>();
            foreach (DataRow item in dt.Rows)
            {
                list.Add(dal.DataRowToModel(item));
            }
            CommModel<CostRegister> ent = new CommModel<CostRegister>();
            ent.Data = list;
            ent.PageCount = Convert.ToInt32(ht["PageCount"]);
            ent.RecordCount = Convert.ToInt32(ht["record"]);
            return ent;
        }
        #endregion
    }
}
